let headerHtml =` <div class="hed_com win_max">
<div class="fix_view">
  <div class="head_left">
    <a class="logo" href="../../index.html"><img src="../../static/img/logo.png" alt="精匠" /></a>
    <div class="search_box">
      <a class="input_box"
        ><span>请输入关键词查询,例如展会活动</span></a
      >
      <a class="s_btn">
        <i class="iconfont icon-chaxun"></i> <span>搜索</span>
      </a>
    </div>
  </div>
  <div class="head_right">
    <a class="r_a">联系我们</a>
    <a class="r_a" href="../../home/login/index.html">注册/登录</a>
  </div>
</div>
</div>` 
$('#header').append(headerHtml);

$(document).ready(function () {
    getCommentList();
    $(document).on('click', '.praise_comment', function() {
        let id  = $(this).attr('data-id');
        cancelPraiseComment(id)
    });
});

function getIdFromUrl(v) {
    // 创建一个新的URL对象
    var url = new URL(window.location.href);
   
    // 使用searchParams获取URL中的查询参数
    var params = new URLSearchParams(url.search);
 
    return params.get(v);
  }
 
   
function getCommentList(){
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/common.comments/list',
        http_type: 'POST',
        datas: {
            "type": "100",
            "service_id":"1",
            "page":1,
            "page_size":"15"
        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            $(".comment_content_left").children(".comment_content_left_item").remove();
            for (let i = 0; i < response.data.data.length; i++) {
                let comment_content_left_item = $("<div class='comment_content_left_item'></div>")
                let item_top = $("<div class='item_top'></div>")
                let item_top_div_1 =  $("<div></div>")
                let item_top_div_1_img = $("<img/>")
                $(item_top_div_1_img).attr('src',response.data.data[i].user.avatar)
                let item_top_div_1_span = $("<span></span>")
                $(item_top_div_1_span).text(response.data.data[i].user.nickname);
                $(item_top_div_1).append(item_top_div_1_img)
                $(item_top_div_1).append(item_top_div_1_span)
                $(item_top).append(item_top_div_1)
                let item_top_div_2 =  $("<div></div>")
                let item_top_div_2_img = $("<img src='../../icons/icon_praise.png' style='cursor: pointer' class='praise_comment'/>")
                // $(item_top_div_2_img).attr('src','../icons/icon_praise.png')
                $(item_top_div_2_img).attr('data-id', response.data.data[i].id);
                let item_top_div_2_span = $("<span></span>")
                $(item_top_div_2_span).text(response.data.data[i].love_number);
                let item_top_div_2_div = $("<div></div>")
                $(item_top_div_2_div).text('写看法')
                $(item_top_div_2).append(item_top_div_2_img)
                $(item_top_div_2).append(item_top_div_2_span)
                $(item_top_div_2).append(item_top_div_2_div)
                $(item_top).append(item_top_div_2)
                $(comment_content_left_item).append(item_top)
                let item_bottom = $("<div class='item_bottom'></div>")
                let item_bottom_span_1 = $("<span></span>")
                $(item_bottom_span_1).text(response.data.data[i].content)
                let item_bottom_span_2 = $("<span></span>")
                $(item_bottom_span_2).text('详情'+i)
                $(item_bottom).append(item_bottom_span_1)
                $(item_bottom).append(item_bottom_span_2)
                $(comment_content_left_item).append(item_bottom)
                $('.comment_content_left_search').after(comment_content_left_item);
            }
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}
function praiseComment(id){
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/common.comments_love/create',
        http_type: 'POST',
        datas: {
            'comments_id':id
        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            getCommentList()
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}
function cancelPraiseComment(id){
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/common.comments_love/unlike',
        http_type: 'POST',
        datas: {
            'comments_id':id
        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            getCommentList()
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}
// 获取地区 
function getCommonArea(id){
    var loadIndex = layer.load(2);
    let datas = {
        url: '/api/common/area',
        http_type: 'POST',
        datas: {
            'pid':id
        }
    }
    wxx.HttpReqeust(datas, function (response) {
        layer.close(loadIndex)
        if (response.code == 1) {
            getCommentList()
        } else {
            layer.alert(response.msg, {title: '温馨提示'});
        }
    });
}

 
let emptyHtml =`<div class="page_empty_style align-center">
<div>
    <img src="../../static/img/empty/empty1.svg" alt=""> 
    <div class="empty_tips">暂无数据</div>
</div>
</div>`


// 跳转到发布页面 
$('.jumpToEdit').click(()=>{ 
    window.location.href = '../../editor/releaseEditor.html?id='+getIdFromUrl('id')
})
// 获取省份的ID
var relate_id = localStorage.getItem('brand_category_id') || '71'